package com.pengxh.app.realityshow.media;

import android.media.MediaCodecInfo;

/**
 * @description: TODO
 * @author: Pengxh
 * @email: 290677893@qq.com
 * @date: 2019/12/15 17:42
 */
public class AudioEncoder {
    private static final String TAG = "AudioEncoder";

    private static final int DEFAULT_BIT_RATE = 128 * 1024; //128kb //AAC-LC, 64 *1024 for AAC-HE
    private static final int DEFAULT_SIMPLE_RATE = 44100; //44100Hz
    private static final int DEFAULT_CHANNEL_COUNTS = 1;
    private static final int DEFAULT_MAX_INPUT_SIZE = 16384; //16k
    private static final int DEFAULT_PROFILE_LEVEL = MediaCodecInfo.CodecProfileLevel.AACObjectLC;
    private static final String DEFAULT_MIME_TYPE = "audio/mp4a-latm";


    /**
     * 给编码出的aac裸流添加adts头字段
     *
     * @param packet    要空出前7个字节，否则会搞乱数据
     * @param packetLen
     */
    public void addADTStoPacket(byte[] packet, int packetLen) {
        int profile = 2;  //AAC LC
        int freqIdx = 4;  //44.1KHz
        int chanCfg = 2;  //CPE
        packet[0] = (byte) 0xFF;
        packet[1] = (byte) 0xF9;
        packet[2] = (byte) (((profile - 1) << 6) + (freqIdx << 2) + (chanCfg >> 2));
        packet[3] = (byte) (((chanCfg & 3) << 6) + (packetLen >> 11));
        packet[4] = (byte) ((packetLen & 0x7FF) >> 3);
        packet[5] = (byte) (((packetLen & 7) << 5) + 0x1F);
        packet[6] = (byte) 0xFC;
    }
}
